package com.ruoyi.labdata.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.labdata.domain.LabOrgnizationSecond;
import com.ruoyi.labdata.service.ILabOrgnizationSecondService;

/**
 * 二级机构信息Controller
 * 
 * @author winner pan
 * @date 2022-02-05
 */
@RestController
@RequestMapping("/labdata/orgSecond")
public class LabOrgnizationSecondController extends BaseController
{
    @Autowired
    private ILabOrgnizationSecondService labOrgnizationSecondService;

    /**
     * 查询二级机构信息列表
     */
    @PreAuthorize("@ss.hasPermi('labdata:orgSecond:query')")
    @GetMapping("/list")
    public TableDataInfo list(LabOrgnizationSecond labOrgnizationSecond)
    {
        startPage();
        List<LabOrgnizationSecond> list = labOrgnizationSecondService.selectLabOrgnizationSecondList(labOrgnizationSecond);
        return getDataTable(list);
    }

    /**
     * 导出二级机构信息列表
     */
   // @PreAuthorize("@ss.hasPermi('labdata:orgSecond:export')")
   /* @Log(title = "二级机构信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LabOrgnizationSecond labOrgnizationSecond)
    {
        List<LabOrgnizationSecond> list = labOrgnizationSecondService.selectLabOrgnizationSecondList(labOrgnizationSecond);
        ExcelUtil<LabOrgnizationSecond> util = new ExcelUtil<LabOrgnizationSecond>(LabOrgnizationSecond.class);
        return util.exportExcel(list, "orgSecond");
    }*/

    /**
     * 获取二级机构信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('labdata:orgSecond:query')")
    @GetMapping(value = "/{orgId}")
    public AjaxResult getInfo(@PathVariable("orgId") Long orgId)
    {
    	LabOrgnizationSecond labOrgnizationSecond = labOrgnizationSecondService.selectLabOrgnizationSecondById(orgId);
    	LabOrgnizationSecond statsticOrg = labOrgnizationSecondService.getOrgstatsticData(orgId);
    	if(labOrgnizationSecond!=null && statsticOrg!=null){
	    	labOrgnizationSecond.setBuildAreaSum(statsticOrg.getBuildAreaSum());
	    	labOrgnizationSecond.setUsingArea(statsticOrg.getUsingArea());
	    	labOrgnizationSecond.setEmployeeNumSum(statsticOrg.getEmployeeNumSum());
	    	labOrgnizationSecond.setLabNumSum(statsticOrg.getLabNumSum());
    	}
    	return AjaxResult.success(labOrgnizationSecond);
    }

    /**
     * 新增二级机构信息
     */
    @PreAuthorize("@ss.hasPermi('labdata:orgSecond:edit')")
    @Log(title = "二级机构信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabOrgnizationSecond labOrgnizationSecond)
    {
        return toAjax(labOrgnizationSecondService.insertLabOrgnizationSecond(labOrgnizationSecond));
    }

    /**
     * 修改二级机构信息
     */
    @PreAuthorize("@ss.hasPermi('labdata:orgSecond:edit')")
    @Log(title = "二级机构信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabOrgnizationSecond labOrgnizationSecond)
    {
        return toAjax(labOrgnizationSecondService.updateLabOrgnizationSecond(labOrgnizationSecond));
    }

    /**
     * 删除二级机构信息
     */
    @PreAuthorize("@ss.hasPermi('labdata:orgSecond:edit')")
    @Log(title = "二级机构信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orgIds}")
    public AjaxResult remove(@PathVariable Long[] orgIds)
    {
        return toAjax(labOrgnizationSecondService.deleteLabOrgnizationSecondByIds(orgIds));
    }
}
